<?php session_start();?>
<?php error_reporting(E_ALL); ?>
<?php include_once"../Backend/Eventlog.php";?>
<?php include_once"../Backend/Session.php";?>
<!DOCTYPE HTML>

<html>
 <head>

  <title>My Practice HTML Page</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link href="Test.css" rel="stylesheet" type="text/css">
  <meta name="dcterms.Type"          content="Text" />
  <meta name="dcterms.publisher"     content="Marc" />
  <meta name="dcterms.subject"       content="Dublin Core Metadaten-Elemente, Anwendungen" />
  <meta name="dcterms.creator"       content="Marc" />
  <meta name="dcterms.title"         content="Pubvat" />
  <meta name="dcterms.keywords"      content="Kalender" />
  <meta name="dcterms.desciption"    content="Ein Kalender" />
  <meta name="dcterms.contributor"   content="User" />
  <meta name="dcterms.date"          content="2011-12-02"/>
  <meta name="dcterms.format"        content="Kalender"/>
  <meta name="dcterms.identifier"    content="https://pc-martin.it.fh-worms.de:4433/swa20/frontend/Startseite.html" />
  <meta name="dcterms.source"        content="??"/>
  <meta name="dcterms.language"      content="de"/>
  <meta name="dcterms.relation"      content="http://www.google.de"/>
  <meta name="dcterms.coverage"      content="Deutschland"/>
  <meta name="dcterms.rights"        content="www.google.de"/>



</head>

<body id="main">
	<div id="menu">
   	<p> <font size = "7" >LOGO </font></p>
   	&nbsp;

  	</div>

	<div id="register">
		<h1>Register</h1>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			Your email address<br>
			<input type="text" name="newLogin" id="newLoginControl" class="textCtrl" tabindex="100" value="<?php if(isset($_POST['newLogin'])) echo $_POST['newLogin']; ?>">
			<?php 	if(isset($_POST['newLogin']) and ($_POST['newLogin'] == "")){
						echo "This field cannot be empty!";
						$mailValidate = 0;
					} elseif(isset($_POST['newLogin']) and (filter_var($_POST['newLogin'], FILTER_VALIDATE_EMAIL) == "")){
						echo "This mail is incorrect!"; 
						$mailValidate = 0;
					} elseif(!isset($_POST['newLogin'])){
						$mailValidate = 0;
					} else {
						$mailValidate = 1;
					}?><br>
			Your name<br>
			<input type="text" name="newName" id="newName" class="textCtrl" tabindex="200" value="<?php if(isset($_POST['newName'])) echo $_POST['newName']; ?>">
			<?php 
				if(isset($_POST['newName']) and ($_POST['newName'] == "")) {
					$nameValidate = 0;
					echo "This field cannot be empty!";
				} else {
					$nameValidate = 1;
				}
			?><br>
			Your password<br>
			<input type="password" name="newPassword" class="textCtrl" id="newCtrl_password" tabindex="300" value="<?php if(isset($_POST['newPassword'])) echo $_POST['newPassword']; ?>"><br>
			Confirm password<br>
			<input type="password" name="confirmPassword" class="textCtrl" id="newCtrl_confirmPassword" tabindex="400" value="<?php if(isset($_POST['confirmPassword'])) echo $_POST['confirmPassword']; ?>">
			<?php 
				if((isset($_POST['newPassword']) and ($_POST['newPassword'] == "")) or (isset($_POST['confirmPassword']) and ($_POST['confirmPassword'] == ""))){
					$passValidate = 0;
					echo "The password fields cannot be empty!";
				} elseif(((isset($_POST['newPassword']) and (isset($_POST['confirmPassword'])))) and (($_POST['newPassword']) != ($_POST['confirmPassword']))) {
					$passValidate = 0;
					echo "Passwords must be identical!";
				} else {
					$passValidate = 1;
				}
			?><br>
			<input type="submit" name ="send" class="button primary" value="Register" tabindex="500" data-loginphrase="Log in" data-signupphrase="Sign Up">
		</form>
		<?php
			if(isset($_POST["newLogin"], $_POST["newName"], $_POST["newPassword"], $_POST["confirmPassword"])){
				$email = $_POST["newLogin"];
				$name = $_POST["newName"];
				$pass = $_POST["newPassword"];
				$confPass = $_POST["confirmPassword"];
				if(($mailValidate == 1) and ($nameValidate == 1) and ($passValidate == 1)){ 
					Eventlog::writeEventlog("Register as: ".$email);
					Eventlog::writeEventlog("with name: ".$name);
					Eventlog::writeEventlog("with password: ".$pass);
					Eventlog::writeEventlog("with confirmPassword: ".$confPass);
					
					$session = new Session();
					$session->register($email, $name, $pass);
					echo "Congrats! Registration Successful!<br>";
					$_SESSION['password'] = $pass;
					$_SESSION['email'] = $email;
					echo "<a href='Folgeseite.php' name='nextSite'>You want to change to the next Site?!</a><br>";
					echo "<a href='Startseite.php' name='startSite'>Click here to get to the Loginsite!</a><br>";
				}
			} else {
				Eventlog::writeEventlog("isSet Fail");
			}
		?> 

  </div>

 </body>

</html>